/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sda.levelup.actions;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIManager;

/**
 *
 * @author user
 */
public class MainFrame extends JFrame
{

    public MainFrame()
    {
        setSize(300, 150);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        fillFrame();
    }

    public void fillFrame()
    {
        textPanel tp = new textPanel();
        add(tp);
    }

    class textPanel extends JPanel
    {

        JTextField ta;
        UIManager UI;

        public textPanel()
        {
            UI = new UIManager();
//            UI.put("OptionPane.background", Color.white);
//            UI.put("Panel.background", Color.white);
            setLayout(new BorderLayout());
            Box up = Box.createVerticalBox();
            up.add(fillText());
            up.add(colorButtons());
            add(up, BorderLayout.NORTH);
            add(showButton(), BorderLayout.SOUTH);

        }

        public JPanel fillText()
        {
            JLabel label = new JLabel("Text:");
            ta = new JTextField(10);
            JPanel text = new JPanel();
            text.add(label);
            text.add(ta);
            return text;
        }

        public JPanel showButton()
        {
            JPanel showPan = new JPanel();
            JButton show = new JButton("Show");
            show.addActionListener(new ActionListener()
            {

                @Override
                public void actionPerformed(ActionEvent ae)
                {
                    JOptionPane.showMessageDialog(null, ta.getText(), "Mess", JOptionPane.ERROR_MESSAGE, null);
                }
            });
            showPan.add(show);
            return showPan;
        }

        public JPanel colorButtons()
        {
            JPanel colorButtons = new JPanel();
            ButtonGroup group = new ButtonGroup();
            JRadioButton red = new JRadioButton("Red");
            JRadioButton green = new JRadioButton("Green");
            JRadioButton yellow = new JRadioButton("Yellow");
            red.addActionListener(new ActionListener()
            {

                @Override
                public void actionPerformed(ActionEvent ae)
                {
                    UI.put("OptionPane.messageForeground", Color.red);
                }
            });
            green.addActionListener(new ActionListener()
            {

                @Override
                public void actionPerformed(ActionEvent ae)
                {
                   UI.put("OptionPane.messageForeground", Color.GREEN);
                }
            });
            yellow.addActionListener(new ActionListener()
            {

                @Override
                public void actionPerformed(ActionEvent ae)
                {
                   UI.put("OptionPane.messageForeground", Color.yellow); 
                }
            });
            group.add(red);
            group.add(green);
            group.add(yellow);
            colorButtons.add(red);
            colorButtons.add(green);
            colorButtons.add(yellow);
            return colorButtons;
        }
    }
}
